<?php
class DvutcbsController extends AppController {

	var $name = 'Dvutcbs';

	function index() {
		$this->Dvutcb->recursive = 0;
		$this->set('dvutcbs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid dvutcb', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('dvutcb', $this->Dvutcb->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Dvutcb->create();
			if ($this->Dvutcb->save($this->data)) {
				$this->Session->setFlash(__('The dvutcb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The dvutcb could not be saved. Please, try again.', true));
			}
		}
		$canbos = $this->Dvutcb->Canbo->find('list');
		$namhocs = $this->Dvutcb->Namhoc->find('list');
		$this->set(compact('canbos', 'namhocs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid dvutcb', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Dvutcb->save($this->data)) {
				$this->Session->setFlash(__('The dvutcb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The dvutcb could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Dvutcb->read(null, $id);
		}
		$canbos = $this->Dvutcb->Canbo->find('list');
		$namhocs = $this->Dvutcb->Namhoc->find('list');
		$this->set(compact('canbos', 'namhocs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for dvutcb', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Dvutcb->delete($id)) {
			$this->Session->setFlash(__('Dvutcb deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Dvutcb was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>